<?php
/**
 * $Id: map.php 428 2009-12-22 13:44:53Z shrey $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * This is parent of parent class of a controller and should not be edited ever without permission.
 * @version 			$Rev: 428 $
 * @lastModifiedBy		$LastChangedBy: shrey $
 * @lastChanged			$Date: 2009-12-22 19:14:53 +0530 (Tue, 22 Dec 2009) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

/**
 * Use to display map with location pointers
 *
 */
class MapHelper extends Helper
{

    var $helpers = array('Html');
	/* $options for class variable in only those varaible that don't need 
	to be itrate in foreach($locations) */
    function displaymap($locations=false,$options=array(), $width=700,$height=400, $polylines=false)
    {
		require_once(APP.'plugins'.DS.'cms'.DS.'vendors'.DS.'GoogleMapAPI.php');
		$map = new GoogleMapAPI('map');
		
		// set api key
		if(Configure::read('cmsConfig.Miscellaneous.mapApiKey') != '')
		{
			$map->setAPIKey(Configure::read('cmsConfig.Miscellaneous.mapApiKey'));
		}
		
		$i=0;
		
		if(is_array($locations))
		{
			// polylines should work when marker is also added
			foreach($locations as $location)
			{
				//set polylines 1 on calling displaymap 
				if($polylines==true)
					$map->addPolyLineByAddress($location['address'], @$locations[$i++]['address'], "#ff0000", 2, 90);

				$map->addMarkerByAddress( $location['address'],strip_tags($location['title']), $location['title']);  
				//adds address to showup in Map
				if(isset($location['marker']) && $location['marker']!='')
					$map->addMarkerIcon($location['marker']);
			}

		}
			
			
		$map->setWidth($width);
		$map->setHeight($height);
		if(!empty($options))
		{
			foreach($options as $mapVar =>$value )
			{
				$map->{$mapVar}=$value;
			}
		}
		
		$map_content= $map->getHeaderJS().$map->getMapJS().$map->getMap();
		return $this->output($map_content);
    }
}
?>
